import 'package:elevator/get/intl_keys.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_expandable_table/flutter_expandable_table.dart';
import 'package:get/get.dart';

import '../../../../../../model/build_info.dart';
import '../../../../../../model/lift_info.dart';
import 'messages_logic.dart';

class MessagesPage extends StatelessWidget {
  late Size size;
  double itemWidth = 60;
  late MessagesLogic logic;

  MessagesPage({Key? key,required BuildInfo buildInfo, required LiftInfo liftInfo}) : super(key: key){
    Get.delete<MessagesLogic>();
    logic = Get.put(MessagesLogic());
    logic.buildInfo = buildInfo;
    logic.liftInfo = liftInfo;
  }

  @override
  Widget build(BuildContext context) {
    size = MediaQuery.of(context).size;
    itemWidth = (size.width - 12 * 2) / 4;
    logic.itemWidth = itemWidth;
    logic.initController();
    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          Container(
            decoration: BoxDecoration(
              color: Colors.green,
              borderRadius: BorderRadius.circular(2),
            ),
            margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 12),
            child: Container(
              padding: const EdgeInsets.fromLTRB(4, 0, 2, 0),
              child: Flex(
                mainAxisAlignment: MainAxisAlignment.end,
                crossAxisAlignment: CrossAxisAlignment.center,
                direction: Axis.horizontal,
                children: [
                  Expanded(
                      flex: 6,
                      child: Text(
                        IntlKeys.lastMonthInfoTitle.tr,
                        style: const TextStyle(color: Colors.white),
                      )
                  ),
                Obx(() { return ButtonBar(
                    buttonPadding: const EdgeInsets.fromLTRB(4, 6, 4, 6),
                    overflowButtonSpacing:1,
                    children: <Widget>[
                      RawMaterialButton(
                        onPressed: () {logic.oneMonth();},
                        fillColor: logic.selectOneMonth.value? Colors.orangeAccent:Colors.blueGrey,
                        child: Text(IntlKeys.oneMonth.tr,style: const TextStyle(color: Colors.white)),
                      ),
                      RawMaterialButton(
                        onPressed: () {logic.halfaMonth();},
                        fillColor: logic.selectOneMonth.value? Colors.blueGrey:Colors.orangeAccent,
                        child: Text(IntlKeys.halfAMonth.tr,style: const TextStyle(color: Colors.white)),
                      ),

                    ],
                  );}),
                ],
              ),
            )
          ),
          Expanded(
            child: Container(
              color: Colors.white,
              margin: EdgeInsets.only(left: 12,right: 12),
              child: Center(
                child: _buildSimpleTable(),
              ),
            ),
          ),
          const SizedBox(height: 96,)
        ],
      ),
    );
  }

  ExpandableTable _buildSimpleTable() {

    return ExpandableTable(
      controller: logic.controller,
    );
  }

}
